﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Net;
using System.Web;

namespace Gtkj.CMS.Common
{
    /// <summary>
    /// 酒店接口帮助类
    /// </summary>
    public  class HotelHelper
    {
        private static string userid = "lizhihu";
        private static string password = "chufeng66621777";
        private static string officeid = "SHF537";

        public static string SendRequest(string requestStr)
        {
            //设置用户信息
            requestStr = SetUserInfo(requestStr);

            //将输入的xml内容转化为byte数组
            string url = "http://dlink.sohoto.com/directlink/send.do";
            byte[] data = System.Text.Encoding.UTF8.GetBytes(requestStr);
            WebRequest request = WebRequest.Create(url);
            request.Method = "POST";
            request.ContentType = "application/x-www-form-urlencoded";
            request.ContentLength = data.Length;

            //利用二进制流发送数据   
            using (Stream newStream = request.GetRequestStream())
            {
                newStream.Write(data, 0, data.Length);
                newStream.Close();
            }

            string respStr = String.Empty;
            WebResponse resp = request.GetResponse();
            using (StreamReader reader = new StreamReader(resp.GetResponseStream()))
            {
                respStr = reader.ReadToEnd();
                return respStr;
            }
        }

        private static string SetUserInfo(string requestStr)
        {
            return requestStr.Replace("[UserID]", userid).Replace("[Password]", password).Replace("[OfficeID]", officeid);
        }
    }
}